<?php
	if(!isset($_SESSION['loggedin'])){
		//header('Location: index.php');	
	}
  echo '
  <script type="text/javascript">
    var MSG_CONFIRM_DELETE="'.$lang['CONFIRM_DELETE_VIP_T'].'";
  </script>';
 
    
    include_once('functions.php');
	$dispAll =true;
	$id = null;
	$isEdit = false;
	if(isset($_POST['ins'])){
        if(hasAccess('add_vips_t')){
            createNewVipT();
        }
    } else if(isset($_POST['upd']) && isset($_POST['id'])){
        if(hasAccess('edit_vips_t')){
           updateVipT();
           $dispAll = false;
           $id = $_POST['id'];
        }
    } else if(isset($_POST['disp']) && isset($_POST['id'])){
       $dispAll = false;
       $id = $_POST['id'];
    } else if(isset($_POST['edit']) && isset($_POST['id'])){
       $dispAll = false;
       $id = $_POST['id'];
       $isEdit =true;
    } else if(isset($_POST['del']) && isset($_POST['id'])){
        if(hasAccess('del_vips_t')){
            deleteVipT();
        }
    }else if(isset($_POST['new'])){
        if(hasAccess('add_vips_t')){
             $dispAll = false;
        }
    }
    if(!$dispAll){
        echo '<table class="table_main">
                <tr>
                    <td>';
        showVipTDetails($id, $isEdit);
        echo '      </td>
                </tr>
            </table>
            <br /><br />';   
    }
    
    $table_name = $prefix.'_VIP_TMPL';
    $query = 'SELECT id, name  FROM '.$table_name;
  
	$result = mysql_query($query);
	if(!$result) {
		$error = mysql_error();
		mysql_close();
		echo '<br/>';
		die($error);
	}
	
    if(hasAccess('add_vips_t')){
        echo '<form class="fill80" method="POST" action="main.php?action=vip_t">
            <input class="btn" type="submit" name="new" value="'.$lang['ADD_NEW_VIP_T'].'" />
        </form>';
    }
    echo '<table class="half table_main" >';
    while($record = mysql_fetch_array($result)){
        echo '
            <tr>
                <th class="fill'.($id==$record['id']?' selected':'').'">'.$record['name'].'</th>
                <td class="fill center">
                    <form class="fill small_form" name="vip_t_'.$record['id'].'"  id="vip_t_'.$record['id'].'" method="POST" action="main.php?action=vip_t">
                        <input type="hidden" name="id" value="'.$record['id'].'" />
                        <table class="center fill">
                            <tr>
                                <td>
                                    <input class="btn" type="submit" name="disp" value="'.$lang['B_DETAILS'].'"/>
                                </td>';
                    if (hasAccess('edit_vips_t')){
                        echo '  <td>
                                    <input class="btn" type="submit" name="edit" value="'.$lang['B_EDIT'].'" />
                                </td>';
                    }  
                    if (hasAccess('del_vips_t')){
                        echo '  <td>
                                    <input class="btn" type="submit" name="del" value="'.$lang['B_DELETE'].'" onclick="return confirmDelete()" />
                                </td>';
                    }   
                    echo '</tr>
                        </table>
                    </form>
                </td>
            </tr>'; 
    }
    echo '</table>';
    

?>